#include "FileChange.h"
#include <QFileInfo>
#include <QDateTime>

CFileChange::CFileChange()
{
	m_bNeedJudge = false;
}


CFileChange::~CFileChange()
{
}
void CFileChange::AddFile2OB(string strFilePath)
{
	if (m_bNeedJudge)
	{
		m_filePath = strFilePath;
		m_lastmodifytime = CFileChange::GetFileModefyTime(strFilePath);
	}
}
bool CFileChange::BFileModify()
{
	if (!m_bNeedJudge)
	{
		return false;
	}
	if (m_lastmodifytime != CFileChange::GetFileModefyTime(m_filePath))
	{
		return true;
	}
	return false;
}
void CFileChange::UpdateModifyTime()
{
	if (!m_bNeedJudge)
	{
		return ;
	}
	m_lastmodifytime = CFileChange::GetFileModefyTime(m_filePath);
}
string CFileChange::GetFilepath()
{
	return m_filePath;
}
string CFileChange::GetFileModefyTime(string strFilePath)
{
	if (!m_bNeedJudge)
	{
		return "";
	}
    QFileInfo fileinfo(strFilePath.c_str());
    QDateTime mdt = fileinfo.lastModified();

    char valueCHARS[256] = { 0 };
    sprintf(valueCHARS,
            "%04d-%02d-%02d %02d:%02d:%02d",
            mdt.date().year(),
            mdt.date().month(),
            mdt.date().day(),
            mdt.time().hour(),
            mdt.time().minute(),
            mdt.time().second());

    return valueCHARS;
}
bool CFileChange::NeedJudge()
{
	return m_bNeedJudge;
}
void CFileChange::SetJudge(bool bJudge)
{
	m_bNeedJudge = bJudge;
}
